<template>
    <div class="header" :style="{
        backgroundImage: pageRouter === '/home' ? 'none' : `url(${headerBg})`,
        position: pageRouter === '/home' ? 'absolute' : ' static'
    }">
        <div class="menu">
            <div class="leftImage" @click="goHome()"><img src="@/assets/logo.png" alt=""></div>
            <div class="rightNav">
                <ul class="nav">
                    <li>
                        <router-link to="/about" class="link-en">About us</router-link>
                        <router-link to="/about" class="link-cn">关于我们</router-link>

                    </li>
                    <li>
                        <router-link to="/project?id=0" class="link-en">Case</router-link>
                        <router-link to="/project?id=0" class="link-cn">项目案例</router-link>
                        <div class="project-list">
                            <div><router-link to="/project?id=1">室内设计</router-link></div>
                            <div><router-link to="/project?id=2">建筑设计</router-link></div>
                            <div><router-link to="/project?id=3">文创街区</router-link></div>
                        </div>
                    </li>
                    <li>
                        <router-link to="/institute" class="link-en">College</router-link>
                        <router-link to="/institute" class="link-cn">研究所</router-link>
                    </li>
                    <li><router-link to="/contact" class="link-en">Contact Us</router-link>
                        <router-link to="/contact" class="link-cn">联系我们</router-link>
                    </li>
                </ul>
                <div class="search"><input type="text" placeholder="请输入内容"> <img src="@/assets/seach.png" alt="">
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import headerBg from '@/assets/headerBg.jpg';
const router = useRouter()
const pageRouter = ref(router.currentRoute._value.fullPath)
// console.log(pageRouter.value === "/home");
// 监听路由变化
watch(
    () => router.currentRoute.value.fullPath, // 正确监听 currentRoute
    (newRoute) => {
        pageRouter.value = newRoute;
        // console.log('Updated pageRouter:', pageRouter.value); // 确认是否有更新
    }
);

onMounted(() => {
    pageRouter.value = router.currentRoute._value.fullPath;
});
const goHome = () => {
    router.push({ name: 'home' })
}
</script>

<style lang="scss" scoped>
.header {
    // position: absolute;
    width: 100%;
    // background-image: url("../assets/headerBg.jpg");
    height: 140px;
    background-size: cover;
    /* 让图片覆盖盒子 */
    background-repeat: no-repeat;
    /* 防止图片重复 */
    background-position: center;
    /* 图片居中显示 */


    .menu {
        display: flex;
        position: absolute;
        justify-self: space-between;
        align-items: center;
        top: 30px;
        left: 50%;
        width: 75vw;
        height: 54px;
        transform: translateX(-50%);
        z-index: 1000;
        // background-color: pink;

        .leftImage {
            width: 50%;
            height: 100%;
            cursor: pointer;
            /* 鼠标悬停时变成手指图标 */
        }

        .rightNav {
            // background-color: blue;
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 50%;
            height: 100%;
            // color: white;

            .nav {
                display: flex;
                justify-content: start;
                align-items: center;
                color: white;
                font-size: 0.8rem;
                position: relative;



                li {
                    position: relative;
                    margin-right: 40px;
                    width: 5rem;

                    .link-cn,
                    .link-en {
                        position: absolute;
                        transition: all 0.3s ease;
                    }

                    .link-cn {
                        top: -9px;
                        opacity: 1;
                    }

                    .link-en {
                        top: -9px;
                        opacity: 0;
                        transform: perspective(1rem) rotateX(-90deg);
                        width: 20rem;
                        height: 0;
                    }

                    &:hover {
                        .link-cn {
                            top: -25px;
                            opacity: 0;
                        }

                        .link-en {
                            opacity: 1;
                            transform: perspective(1rem) rotateX(0deg); // 旋转回正常状态
                            width: 5rem;
                            height: auto;
                        }
                    }

                    .project-list {
                        display: none;
                        /* 默认隐藏项目列表 */
                        position: absolute;
                        /* 定位项目列表 */
                        top: 100%;
                        left: -15px;
                        /* 确保项目列表位于 '项目案例' 下面 */
                        justify-content: start;
                        align-items: start;
                        flex-direction: column;
                        padding-top: 10px;
                        width: 80px;

                        /* 主轴垂直 */
                        div {
                            padding: 12px 0 12px 0;
                            background-color: rgba(67, 67, 67, .7);
                            width: 100%;
                            text-align: center;
                            margin-bottom: 3px;
                        }
                    }

                    &:hover {
                        .project-list {
                            display: flex;
                            /* 鼠标悬停时显示项目列表 */
                        }
                    }
                }
            }

            .search {
                display: flex;
                align-items: center;
                width: 180px;
                height: 44px;
                // background-color: blue;
                border-radius: 22px;
                border: 1px solid white;

                input {
                    margin-right: 10px;
                    width: 80%;
                    color: #999;
                }

                input[type="text"] {
                    background-color: transparent;
                    /* 设置背景为透明 */
                    border: none;
                    /* 去除边框 */
                    outline: none;
                    /* 去除点击时的边框 */
                    font-size: 16px;
                    /* 调整输入文本的字体大小 */
                    padding: 8px;
                    /* 可选：增加内边距 */
                    margin-left: 22px;
                }

                /* 调整 placeholder 提示语的样式 */
                input[type="text"]::placeholder {
                    font-size: 15px;
                    /* 扩大提示语字体大小 */
                    color: #999;
                    /* 可选：设置提示语的颜色 */
                    opacity: 1;
                    /* 确保提示文字不透明 */
                }

                img {
                    width: 40px;
                    height: 40px;
                    color: rgb(255, 255, 255);
                    margin-right: 5px;
                }
            }
        }
    }
}
</style>